package bookSystem.operations;

import bookSystem.book.Book;
import bookSystem.book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    //借阅图书
    public void work(BookList bookList){
        System.out.println("借阅图书");
        System.out.print("请输入要借阅的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (name.equals(book.getName())){
                System.out.println(book.toString());
                if (book.isBorrowed() == false){
                    book.setBorrowed(true);
                    System.out.println("借书成功");
                    System.out.println(book.toString());
                }else{
                    System.out.println("该书已被借出");
                }
            }
        }
    }
}
